using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.TeamFoundation.Build.Client;
using Pegasus.Windows.Forms;

namespace RollManager.Library.Dialogs
{
    public partial class ChooseBuildDialog : FormEx
    {
        public IBuildDetail SelectedBuild
        {
            get
            {
                if( buildList.SelectedRows.Count > 0 )
                {
                    return (IBuildDetail) buildList.SelectedRows[ 0 ].DataBoundItem;
                }

                return null;
            }
        }

        public ChooseBuildDialog( List<IBuildDetail> builds ) : base( "rollManagerConfig.chooseBuildDialog" )
        {
            InitializeComponent();

            buildList.AutoGenerateColumns = false;
            buildList.DataSource = builds;
        }

        private void ChooseFolderDialog_FormClosing( object sender, FormClosingEventArgs e )
        {
            if( SelectedBuild == null && DialogResult == DialogResult.OK )
            {
                e.Cancel = true;
            }
        }

        private void okButton_Click( object sender, EventArgs e )
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        private void cancelButton_Click( object sender, EventArgs e )
        {
            Close();
        }

        private void buildList_DoubleClick( object sender, EventArgs e )
        {
            if( SelectedBuild != null )
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
    }
}